/*
 * SQLUtils.java
 *
 * Created on 1 maggio 2007, 9.38
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package fnUtils;

/**
 *
 * @author franic
 */

public final class SQLUtils {
    
    // metodi per evitare la SQL Injection
    public static String toDB(String i) {
        i = i.replace("'","{1]");
        i = i.replace("\"" ,"{2]");
        i = i.replace("d","{3]"); // per drop...
        i = i.replace("D","{4]");
        i = i.replace("r","{5]"); //...from...
        i = i.replace("R","{6]");
        i = i.replace("e","{7]"); //...select...
        i = i.replace("E","{8]");
        i = i.replace(";","{9]");
        i = i.replace("-","{10]");
        i = i.replace("+","{11]");
        i = i.replace("*","{12]");
        i = i.replace("(","{13]");
        i = i.replace(")","{14]");
        i = i.replace("=","{15]");
        i = i.replace(">","{16]");
        i = i.replace("<","{17]");
        i = i.replace("@","{18]");
        return i;
    }
    
    public static String fromDB(String i) {
        i = i.replace("{1]","'");
        i = i.replace("{2]","\"");
        i = i.replace("{3]","d"); // per drop...
        i = i.replace("{4]","D");
        i = i.replace("{5]","r"); //...from...
        i = i.replace("{6]","R");
        i = i.replace("{7]","e"); //...select...
        i = i.replace("{8]","E");
        i = i.replace("{9]",";");
        i = i.replace("{10]","-");
        i = i.replace("{11]","+");
        i = i.replace("{12]","*");
        i = i.replace("{13]","(");
        i = i.replace("{14]",")");
        i = i.replace("{15]","=");
        i = i.replace("{16]",">");
        i = i.replace("{17]","<");
        i = i.replace("{18]","@");
        return i;
    }
}
